package com.zzyl.web.chatApi.controller;

import com.zzyl.web.chatApi.dto.ChatRequest;
import com.zzyl.web.chatApi.dto.ChatResponse;
import com.zzyl.web.chatApi.exception.ApiException;
import com.zzyl.web.chatApi.service.DeepSeekService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api/chat")
@RequiredArgsConstructor
public class ChatController {
    private final DeepSeekService deepSeekService;

    @PostMapping
    public ResponseEntity<ChatResponse> chat(@RequestBody ChatRequest request) {
        try {
            ChatResponse response = deepSeekService.chatCompletion(request);
            return ResponseEntity.ok(response);
        } catch (IOException e) {
            throw new ApiException("API通信异常: " + e.getMessage());
        }
    }
}
